+2005-08-15 Øyvind Kolås <pippin@gimp.org>
+
+ * babl/babl-classes.h: BablPixelFormat: changed order of attributes to
+ match BablModel. BablFish: removed **from and **to lists, since they
+ were added at a wrong offset from the instance start anyways.
+ * babl/babl-fish.c: Made the reference fish work for linear buffers
+ with constant datatype
+ * babl/babl-ids.h: added BABL_RGBA_DOUBLE
+ * babl/babl-image.[ch]: made BablImage be allocated in a single chunk,
+ added babl_image_new_from_linear()
+ * babl/babl-type.c: added assertion about bits%8==0
+ * babl/babl-base/babl-base-conversions-model.c: made BABL_PLANAR_SANITY accept
+ single band buffers. added conversions for premultiplied grayscale.
+ * babl/babl-base/babl-base-pixel-formats.c: added "rgba-double"
+
2005-08-15 Øyvind Kolås <pippin@gimp.org>
* Makefile-mini: compile both the nop and introspect programs by
BablInstance instance;
BablConversion **from; /*< NULL terminated list of conversions from class */
BablConversion **to; /*< NULL terminated list of conversions to class */
- int planar;
int bands;
+ int planar;
BablModel **model;
BablComponent **component;
BablType **type;
typedef struct
{
BablFish fish;
- BablConversion **from; /*< these are here for a later stage, when calculated*/
- BablConversion **to; /*< reference conversions can be used for "segment" */
- /*< conversions where no other conversions exist. */
BablConversion *type_to_double;
BablConversion *model_to_rgba;
BablConversion *rgba_to_model;
#include "babl-type.h"
#include "babl-model.h"
+#include "babl-image.h"
+#include "babl-pixel-format.h"
static int
each_babl_fish_destroy (Babl *babl,
void *fooB;
void *fooC;
+#define BABL_MAX_BANDS 32
+
int
babl_fish_process (BablFish *babl_fish,
void *source,
int n)
{
Babl *babl;
+ BablImage *imageA;
+ BablImage *imageB;
+ BablImage *imageC;
- fooA = malloc(1000);
- fooB = malloc(1000);
- fooC = malloc(1000);
+ fooA = babl_malloc(sizeof (double) * n * 4);
+ fooB = babl_malloc(sizeof (double) * n * 4);
assert (source);
assert (destination);
fooA,
n* ((BablPixelFormat*)(babl_fish->source))->bands
);
+
/* calculate planar representation of fooA, and fooB */
+
+ imageA = babl_image_new_from_linear (fooA,
+ (Babl*) ((BablPixelFormat*) babl->fish.source)->model[0]);
+ imageB = babl_image_new_from_linear (fooB, (Babl*)babl_model_id (BABL_RGBA));
/* transform fooA into fooB fooB is rgba double */
+
+ ((BablConversion*)(babl->reference_fish.model_to_rgba))->function.planar(
+ imageA->bands,
+ imageA->data,
+ imageA->pitch,
+ imageB->bands,
+ imageB->data,
+ imageB->pitch,
+ n);
+ babl_free (imageA);
+ babl_free (imageB);
+
/* calculate planar representation of fooC */
/* transform fooB into fooC fooC is ???? double */
+ imageB = babl_image_new_from_linear (fooB, (Babl*)babl_model_id (BABL_RGBA));
+ imageC = babl_image_new_from_linear (fooA, (Babl*)((BablPixelFormat*)babl->fish.destination)->model[0]);
+
+ ((BablConversion*)(babl->reference_fish.rgba_to_model))->function.planar(
+ imageB->bands,
+ imageB->data,
+ imageB->pitch,
+ imageC->bands,
+ imageC->data,
+ imageC->pitch,
+ n);
+
+
((BablConversion*)(babl->reference_fish.double_to_type))->function.linear(
fooA, destination, n * ((BablPixelFormat*)(babl_fish->destination))->bands
);
+ babl_free (imageB);
+ babl_free (imageC);
+
+ babl_free (fooA);
+ babl_free (fooB);
return 0;
}
BABL_SRGBA,
BABL_RGB_FLOAT,
BABL_RGBA_FLOAT,
+ BABL_RGBA_DOUBLE,
BABL_CMYK_FLOAT,
BABL_CMYKA_FLOAT,
BABL_YUV420,
each_babl_image_destroy (Babl *babl,
void *data)
{
- babl_free (babl->image.component);
- babl_free (babl->image.pitch);
- babl_free (babl->image.stride);
babl_free (babl);
return 0; /* continue iterating */
Babl *self;
int band;
- self = babl_calloc (sizeof (BablImage), 1);
+ self = babl_calloc (
+ sizeof (BablImage) +
+ sizeof (BablComponent*) * (bands+1) +
+ sizeof (void*) * (bands+1) +
+ sizeof (int) * (bands+1) +
+ sizeof (int) * (bands+1),1);
+
+ self->image.component = ((void *)self) + sizeof (BablImage);
+ self->image.data = ((void *)self->image.component) + sizeof (BablComponent*) * (bands+1);
+ self->image.pitch = ((void *)self->image.data) + sizeof (void*) * (bands+1);
+ self->image.stride = ((void *)self->image.pitch) + sizeof (int) * (bands+1);
+/*self->image.foo = ((void *)self->image.stride) + sizeof (int) * (bands+1);*/
self->class_type = BABL_IMAGE;
self->instance.id = 0;
self->image.bands = bands;
- self->image.component = babl_malloc (sizeof (BablComponent*) * (bands+1));
- self->image.data = babl_malloc (sizeof (void*) * (bands+1));
- self->image.pitch = babl_malloc (sizeof (int) * (bands+1));
- self->image.stride = babl_malloc (sizeof (int) * (bands+1));
-
for (band=0; band < bands; band++)
{
self->image.component[band] = component[band];
return (BablImage*) self;
}
+BablImage *
+babl_image_new_from_linear (void *buffer,
+ Babl *babl)
+{
+ BablImage *self;
+ int band;
+ BablComponent *component [BABL_MAX_BANDS];
+ void *data [BABL_MAX_BANDS];
+ int pitch [BABL_MAX_BANDS];
+ int stride [BABL_MAX_BANDS];
+
+ int offset=0;
+ int calc_pitch=0;
+
+ switch (babl->class_type)
+ {
+ case BABL_PIXEL_FORMAT:
+ for (band=0; band < babl->pixel_format.bands; band++)
+ {
+ BablType *type = babl->pixel_format.type[band];
+ calc_pitch += (type->bits / 8);
+ }
+
+ for (band=0; band < babl->pixel_format.bands; band++)
+ {
+ BablType *type = babl->pixel_format.type[band];
+
+ component[band] = babl->pixel_format.component[band];
+ data[band] = buffer + offset;
+ pitch[band] = calc_pitch;
+ stride[band] = 0;
+
+ offset += (type->bits / 8);
+ }
+ break;
+ case BABL_MODEL:
+ for (band=0; band < babl->model.components; band++)
+ {
+ calc_pitch += (64 / 8);
+ }
+
+ for (band=0; band < babl->model.components; band++)
+ {
+ component[band] = babl->model.component[band];
+ data[band] = buffer + offset;
+ pitch[band] = calc_pitch;
+ stride[band] = 0;
+
+ offset += (64 / 8);
+ }
+ break;
+ default:
+ babl_log ("%s(): Eeek!", __FUNCTION__);
+ break;
+ }
+
+ self = image_new (babl->model.components, component, data, pitch, stride);
+ return self;
+}
+
BablImage *
babl_image_new (void *first,
...)
void
babl_image_each (BablEachFunction each_fun,
- void *user_data)
+ void *user_data)
{
int i;
return;
void babl_image_destroy (void);
BablImage * babl_image_new (void *first_component,
...);
+
+/* create a new BablImage based on a packed BablPixelFormat (or BablModel assumed to
+ * use only doubles).
+ */
+BablImage *
+babl_image_new_from_linear (void *buffer,
+ Babl *format);
#endif
* Boston, MA 02111-1307, USA.
*/
+#include <string.h>
+#include <stdarg.h>
+#include <assert.h>
+
#include "babl-internal.h"
#include "babl-db.h"
-#include <string.h>
-#include <stdarg.h>
static int
each_babl_type_destroy (Babl *babl,
{
Babl *self;
+ assert (bits != 0);
+ assert (bits % 8 == 0);
+
self = babl_calloc (sizeof (BablType), 1);
self->class_type = BABL_TYPE;
self->instance.id = id;
babl_component ("green"),
babl_component ("blue"),
NULL
- ));
+ )
+ );
babl_fish_process (fish,
grayscale_buf, rgb_buf,